<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>新增优惠券</title>
<!--公共样式开始-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/reset.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/common.css">
	<link rel="stylesheet" href="{$NOW_THEME_URL}/Assets/Plugins/ZTree/css/demo.css" type="text/css">
	<link rel="stylesheet" href="{$NOW_THEME_URL}/Assets/Plugins/ZTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Plugins/FontAwesome/css/font-awesome.min.css">
<!--公共样式结束-->
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/module_form.css">
<link rel="stylesheet" type="text/css" href="{$NOW_THEME_URL}/Assets/Css/page_memberAdd.css">
<script src="{$NOW_THEME_URL}/Assets/Js/jquery.min.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Js/common.js"></script>
<script src="{$NOW_THEME_URL}/Assets/Plugins/Datepicker/wdatePicker.js"></script>
<include file="treeCategory"/>
<include file="treeBrand"/>
<include file="treeProduct"/>
<include file="treeLevel"/>
<include file="treeGroup"/>
</head>

<body>
	<div class="page_header">
		<div class="tabbar">
			<ul class="tab clearfix" tabname="tab1">
				<li class="tabhover" show="tab1_0">基本信息</li>
				<li show="tab1_1">优惠规则</li>
				<li show="tab1_2">详细介绍</li>
			</ul>
		</div>
	</div>
	<div class="page_wraper">
		<div id="tab1_0" fortab="tab1">
			<table cellpadding="0" cellspacing="0" class="module_form" width="600">
				<tr>
					<td class="ele_title"><label for="cardnum">名　　称：<em>*</em></label></td>
					<td class="ele_content">
						<input name="title" value="{$detail.pno}" type="text" id="title" class="form_ele_text width_200"></td>
					<td class="ele_title"><label for="realname">缩略图（4:3）：<em>*</em></label></td>
					<td class="ele_content">
						<a href="" class="upload"><i class="icon-picture"></i>上传缩略图（4:3）</a>
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="leibie">发放数量：<em>*</em></label></td>
					<td class="ele_content">
						<input name="total" value="{$detail.ctitle}" type="text" id="total" class="form_ele_text width_200">
					</td>
					<td class="ele_title"><label for="pinpai">可用次数：</label></td>
					<td class="ele_content">
						<input name="usetime" value="1" readonly type="text" id="usetime" class="form_ele_text width_200">
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="cbprice">开始时间：<em>*</em></label></td>
					<td class="ele_content">
						<input name="begin" value="{$detail.mprice}" type="text" id="begin" class="form_ele_text width_200"
						onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'%y-%M-{%d+1} %H:{%m+20}:%s'})" class="Wdate"></td>
					<td class="ele_title"><label for="lsprice">结束时间：<em>*</em></label></td>
					<td class="ele_content">
						<input name="end" value="{$detail.sprice}" type="text" id="end" class="form_ele_text width_200"
						onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'%y-%M-{%d+1} %H:{%m+20}:%s'})" class="Wdate"></td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">前　　缀：<em>*</em></label></td>
					<td class="ele_content">
						<input name="prefix" value="{$detail.ctitle}" type="text" id="prefix" class="form_ele_text width_200"></td>
					<td class="ele_title"><label for="cbprice">是否启用：<em>*</em></label></td>
					<td class="ele_content">
						<input type="radio" value="1" checked name="isshow" id="isshow">是&nbsp;&nbsp;&nbsp;&nbsp;
						<input type="radio" value="2" name="isshow" id="isshow">否
					</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">类　　型：<em>*</em></label></td>
					<td class="ele_content">
						<select class="width_200 couponType" name="type" id="type">
							<volist name="couponType" id="v">
								<option value="{$key}">{$v}</option>
							</volist>
							
						</select>
					</td>
					<td class="ele_title"><label for="cardnum">领取场景：</label></td>
					<td class="ele_content">
						<select class="width_200" name="scene" id="scene">
							<option value="">请选择</option>
							<volist name="couponSence" id="v"> 
								<option value="{$key}">{$v}</option>
							</volist>
						</select>
					</td>
				</tr>
			</table>
			<div id="type_box" class="type_box"></div>
		</div>
		<div id="tab1_1" fortab="tab1" class="clearfix" style="display:none;">
			<table cellpadding="0" cellspacing="0" class="module_form" width="600">
				<tr>
					<td class="ele_title"><label for="cardnum">使用条件：</label></td>
					<td class="ele_content">
						<select class="width_100" name="rule" id="rule">
							<option value="random">任意一条规则</option>
							<option value="all">所有规则</option>
						</select>
						<select class="width_100" name="rulend" id="rulend">
							<option value="accord">符合</option>
							<option value="unaccord">不符合</option>
						</select>
					</td>
					<td colspan="2">&nbsp;</td>
				</tr>
				<tr>
					<td class="ele_title">
						<input type="checkbox" name="treeCheck" id="treeCheck" value="1" style="float:right"></td>
					<td class="ele_content">
						<select class="width_100" name="treeSelect" id="treeSelect">
							<option value="contain">包含</option>
							<option value="uncontain">不包含</option>
						</select>
						<input type="text" class="form_ele_text width_200" readonly id="citySelTree" onclick="showMenuTree()">
						<a id="menuBtnTree" class="selectTree" href="#" onclick="showMenuTree(); return false;">选择</a>
					</td>
					<td colspan="2">商品分类设定</td>
				</tr>
				<tr>
					<td class="ele_title">
						<input type="checkbox" name="brandCheck" id="brandCheck" value="1" style="float:right"></td>
					<td class="ele_content">
						<select class="width_100" name="brandSelect" id="brandSelect">
							<option value="contain">包含</option>
							<option value="uncontain">不包含</option>
						</select>
						<input type="text" class="form_ele_text width_200" readonly id="citySelBrand" onclick="showBrand()">
						<a id="menuBtnBrand" class="selectTree" href="#" onclick="showBrand(); return false;">选择</a>
					</td>
					<td colspan="2">商品品牌设定</td>
				</tr>
				<tr>
					<td class="ele_title">
						<input type="checkbox" name="productCheck" id="productCheck" value="1" style="float:right"></td>
					<td class="ele_content">
						<select class="width_100" name="productSelect" id="productSelect">
							<option value="contain">包含</option>
							<option value="uncontain">不包含</option>
						</select>
						<input type="text" class="form_ele_text width_200" readonly id="citySelProduct" onclick="showProduct()">
						<a id="menuBtnProduct" class="selectTree" href="#" onclick="showProduct(); return false;">选择</a>
					</td>
					<td colspan="2">特定商品设定</td>
				</tr>
				<tr>
					<td class="ele_title">
						<input type="checkbox" name="levelCheck" id="levelCheck" value="1" style="float:right"></td>
					<td class="ele_content">
						<select class="width_100" name="levelSelect" id="levelSelect">
							<option value="contain">包含</option>
							<option value="uncontain">不包含</option>
						</select>
						<input type="text" class="form_ele_text width_200" readonly id="citySelLevel" onclick="showLevel()">
						<a id="menuBtnLevel" class="selectTree" href="#" onclick="showLevel(); return false;">选择</a>
					</td>
					<td colspan="2">会员等级设定</td>
				</tr>
				<tr>
					<td class="ele_title">
						<input type="checkbox" name="groupCheck" id="groupCheck" value="1" style="float:right"></td>
					<td class="ele_content">
						<select class="width_100" name="groupSelect" id="groupSelect">
							<option value="contain">包含</option>
							<option value="uncontain">不包含</option>
						</select>
						<input type="text" class="form_ele_text width_200" readonly id="citySelGroup" onclick="showGroup()">
						<a id="menuBtnGroup" class="selectTree" href="#" onclick="showGroup(); return false;">选择</a>
					</td>
					<td colspan="2">会员分组设定</td>
				</tr>
				<tr>
					<td class="ele_title">
						<input type="checkbox" name="numCheck" id="numCheck" value="1" style="float:right"></td>
					<td class="ele_content">
						<select class="width_100" name="numSelect" id="numSelect">
							<option value="contain">包含</option>
							<option value="uncontain">不包含</option>
						</select>
						<input type="text" name="orderNum" id="orderNum" class="form_ele_text width_200">
					</td>
					<td colspan="2">订单总数量设定</td>
				</tr>
				<tr>
					<td class="ele_title">
						<input type="checkbox" name="totalCheck" id="totalCheck" value="1" style="float:right"></td>
					<td class="ele_content">
						<select class="width_100" name="totalSelect" id="totalSelect">
							<option value="contain">包含</option>
							<option value="uncontain">不包含</option>
						</select>
						<input type="text" name="orderTotal" id="orderTotal" class="form_ele_text width_200">
					</td>
					<td colspan="2">订单总金额设定</td>
				</tr>
			</table>
		</div>
		<div id="tab1_2" fortab="tab1" class="clearfix" style="display:none;">
			<table cellpadding="0" cellspacing="0" class="module_form" width="600">
				<tr>
					<td class="ele_title"><label for="realname">简　　介：</label></td>
					<td class="ele_content">
						<input type="text" name="description" id="description" class="form_ele_text width_200">
					</td>
					<td colspan="2">请输入优惠券简介</td>
				</tr>
				<tr>
					<td class="ele_title"><label for="realname">详细介绍：</label></td>
					<td class="ele_content">
						<textarea class="width_90" name="content" id="content">{$detail.content}</textarea>
					</td>
					<td colspan="2">&nbsp;</td>
				</tr>
			</table>
		</div>
		
	</div>
	<div class="page_footer pdtd10">
		<input type="button" name="submit" value="提交数据"  class="form_ele_submit"/>
		<input type="reset" name="reset" value="清空数据"  class="form_ele_reset"/>
	</div>
	
	<input type="hidden" name="solevar"      id="solevar" value="{:create_id()}">
	<input type="hidden" name="menuValue"    id="menuValue">
	<input type="hidden" name="brandValue"   id="brandValue">
	<input type="hidden" name="productValue" id="productValue">
	<input type="hidden" name="levelValue"   id="levelValue">
	<input type="hidden" name="groupValue"   id="groupValue">
	
	<div id="menuContent" class="menuContent" style="display:none; position: absolute;">
	<ul id="treeDemo" class="ztree" style="margin-top:0; width:180px; height: 300px;"></ul>
	</div>
	<div id="barndContent" class="barndContent" style="display:none; position: absolute;">
	<ul id="treeBrand" class="ztree" style="margin-top:0; width:180px; height: 300px;"></ul>
	</div>
	<div id="productContent" class="productContent" style="display:none; position: absolute;">
	<ul id="treeProduct" class="ztree" style="margin-top:0; width:180px; height: 300px;"></ul>
	</div>
	<div id="levelContent" class="levelContent" style="display:none; position: absolute;">
	<ul id="treeLevel" class="ztree" style="margin-top:0; width:180px; height: 300px;"></ul>
	</div>
	<div id="groupContent" class="groupContent" style="display:none; position: absolute;">
	<ul id="treeGroup" class="ztree" style="margin-top:0; width:180px; height: 300px;"></ul>
	</div>
	
</body>
<script type="text/javascript" src="{$NOW_THEME_URL}/Assets/Plugins/ZTree/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="{$NOW_THEME_URL}/Assets/Plugins/ZTree/js/jquery.ztree.excheck-3.5.js"></script>
<script type="text/javascript">
	//弹出窗口全局变量
	var api  = frameElement.api, W = api.opener;

	$(function(){
		//滑动门
		$('.tabbar li').click(function(){
			var tabname = $('.tabbar>ul').attr('tabname');
			$('.tabbar li').removeClass('tabhover');
			$(this).addClass('tabhover');
			
			$('div[fortab="'+tabname+'"]').hide();
			
			var showContent = $('#'+$(this).attr('show')); //当前要显示的内容对象
			showContent.show();
		});
		
		//动态改变优惠券规则
		$(".couponType").change(function(){
			if($(this).val()){
				$.get('{:U("Coupon/type")}&val='+$(this).val(), function(data){
					$('.type_box').html(data);	
				});
			}else{
				$('.type_box').html('');	
			}
		})
		
		//新增满减
		$('.addFullCut').live('click',function(){
			var html = '<tr class="preferential FullCut">\
				<td class="ele_title"><label for="cardnum">&nbsp;</label></td>\
				<td class="ele_content">\
				满<input name=""  type="text" id="pno" class="form_ele_text width_50">\
				减<input name=""  type="text" id="pno" class="form_ele_text width_50">\
				</td><td colspan="2"><em>请输入满金额及减金额</em></td></tr>';
				
			$('.information').append(html);
		});
		//新增满送
		$('.addFullSend').live('click',function(){
			var html = '<tr class="preferential fullsend">\
				<td class="ele_title"><label for="cardnum">&nbsp;</label></td>\
				<td class="ele_content">\
				满<input name=""  type="text" id="pno" class="form_ele_text width_50">\
				送<input name=""  type="text" id="pno" class="form_ele_text width_50">\
				</td><td colspan="2"><em>请输入满金额及送金额</em></td></tr>';
				
			$('.information').append(html);
		});
		//新增满折
		$('.addFullDiscount').live('click',function(){
			var html = '<tr class="preferential fulldiscount">\
				<td class="ele_title"><label for="cardnum">&nbsp;</label></td>\
				<td class="ele_content">\
				满<input name=""  type="text" id="pno" class="form_ele_text width_50">\
				折<input name=""  type="text" id="pno" class="form_ele_text width_50">\
				</td><td colspan="2"><em>请输入满金额及折扣</em></td></tr>';
				
			$('.information').append(html);
		});
		
		//初始化加载
		$.get('{:U("Coupon/type","val=cash")}', function(data){
			$('#type_box').html(data);	
		});
		
		//表格隔行换色
		$('.module_form tr:odd').addClass('odd');
		$('.module_form tr:even').addClass('even');

		//重置
		$('.form_ele_reset').on('click',function(){
			$('#productAdd_form').get(0).reset();
		});
		//提交
		$('.form_ele_submit').on('click',function(){
			
			
			var tipsObj = windowApi.lhgdialog.tips('正在提交数据...',2,etIcon.loading);
			
			var attrValue = {};
			$(".attrValue").each(function(i){
				attrValue[i] = $(this).val();
			});
			
			//通过Ajax提交表单
			var postData = {};
			postData.solevar    = $('#solevar').val();    //唯一标识
			postData.title      = $('#title').val();      //名称
			postData.description= $('#description').val();//简介
			postData.content    = $('#content').val();    //详细介绍
			postData.total      = $('#total').val();      //发放数量
			postData.type       = $('#type').val();       //优惠券类型
			postData.prefix     = $('#prefix').val();     //前缀
			postData.scene      = $('#scene').val();      //领取场景
			postData.usetime    = $('#usetime').val();    //使用次数
			postData.end        = $('#end').val();        //结束时间
			postData.begin      = $('#begin').val();      //开始时间
			postData.isshow     = $('#isshow').val();     //是否启用
			postData.rule       = $('#rule').val();       //任意一条规则/所有规则
			postData.rulend     = $('#rulend').val();     //符合/不符合
			postData.attrValue  = attrValue;
			
			if($("#treeCheck").attr("checked")=="checked"){
				postData.menuValue   = $('#menuValue').val();      //分类id
				postData.treeSelect  = $('#treeSelect').val();     //获取是否特价
			}
			if($("#brandCheck").attr("checked")=="checked"){
				postData.brandValue  = $('#brandValue').val();     //品牌id
				postData.brandSelect = $('#brandSelect').val();    //获取是否赠送积分
			}
			if($("#productCheck").attr("checked")=="checked"){
				postData.productValue  = $('#productValue').val();     //分组id
				postData.productSelect = $('#productSelect').val();    //获取是否折扣
			}
			if($("#levelCheck").attr("checked")=="checked"){
				postData.levelValue  = $('#levelValue').val();     //商品id
				postData.levelSelect = $('#levelSelect').val();    //获取是否折扣
			}
			if($("#groupCheck").attr("checked")=="checked"){
				postData.groupValue  = $('#groupValue').val();     //等级id
				postData.groupSelect = $('#groupSelect').val();    //获取是否折扣
			}
			if($("#numCheck").attr("checked")=="checked"){
				postData.orderNum    = $('#orderNum').val();     //订单数量
				postData.numSelect   = $('#numSelect').val();    //获取是否折扣
			}
			if($("#totalCheck").attr("checked")=="checked"){
				postData.orderTotal  = $('#orderTotal').val();     //订单金额
				postData.totalSelect = $('#totalSelect').val();    //获取是否折扣
			}
			
			$.post("{:U('Coupon/add')}", postData ,function(data){
				tipsObj.close();
				frameApi.close(); //关闭当前窗口
				if(data.status==1){
					windowApi.lhgdialog.tips('数据提交成功！',1,etIcon.success,function(){
						var obj = windowApi.lhgdialog.list['Coupon_index'];
						obj.reload(obj);
					});
				}else{
					windowApi.lhgdialog.alert(data.info,function(){return;});
				}
			}, "json");
		});
	});

</script>
</html>
